/**
 * 给显示对象增加统一设置透明度的 alphaPlus 属性
 * */

export default class MyDisplayObject extends egret.DisplayObject {
  // 透明滤镜
  private colorMatrixFilter: egret.ColorMatrixFilter
  private alphaPlusVal: number = 1
  private colorMatrix = [
    1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0,
  ]

  public get alphaPlus(): number {
    return this.alphaPlusVal
  }
  public set alphaPlus(val: number) {
    if (this.alphaPlusVal === val) {
      return
    }
    if (val === 1) {
      this.alphaPlusVal = val
      this.filters = null
      return
    }
    this.alphaPlusVal = val
    this.colorMatrix[18] = this.alphaPlusVal
    if (!this.colorMatrixFilter) {
      this.colorMatrixFilter = new egret.ColorMatrixFilter(this.colorMatrix)
    } else {
      this.colorMatrixFilter.matrix = this.colorMatrix
    }
    this.filters = [this.colorMatrixFilter]
  }
}
